//封装表格汇总行
/**
 * 
 * @param instance  表格实例
 * @param data  表格数据
 * @param headArr  要汇总的表头
 */
const setTableTotalRow = (instance: any, data: any, headArr: any) => {
  const totalRowObj = {
    defaultCkBox: '汇总',
  }
  headArr.forEach((item: any) => {
    totalRowObj[item] = data.reduce((sum: any, cur: any) => {
      if (!cur[item] || isNaN(cur[item])) cur[item] = 0
      return Number(sum) + Number(cur[item])
    }, 0)
  })
  for (let key in totalRowObj) {
    if (key !== 'defaultCkBox' && key !== 'defaultRowNum') totalRowObj[key] = parseFloat(totalRowObj[key]).toFixed(2)
  }
  nextTick(() => {
    instance.value.setPinnedBottomRowData([totalRowObj])
  })
}

export default setTableTotalRow